package dobest.ray.com.jiongjiong.adapter;


import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import dobest.ray.com.jiongjiong.R;
import dobest.ray.com.jiongjiong.bean.BusinessCircleListBean;

public class ServiceLabelAdapter extends BaseAdapter {
	private int mSelectedIndex = 0;
	private Context context;
	private Resources mResources;
	private List<BusinessCircleListBean> data = new ArrayList<BusinessCircleListBean>();

	private String[] moneyTypeStr = { "不限", "0~50", "51~100", "101~150", "151~200", "200以上" };
	/**
	 * 0 商圈，1类型，2价格
	 */
	private int flag = -1;

	public ServiceLabelAdapter(Context context) {
		this.context = context;
		mResources = context.getResources();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public BusinessCircleListBean getItem(int arg0) {
		// TODO Auto-generated method stub
		return data.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.popuwindow_item, null);
		}
		if (flag == -1) {
			return convertView;
		}
		TextView text = (TextView) convertView.findViewById(R.id.name);
		if (position == mSelectedIndex) {
			text.setTextColor(mResources.getColor(R.color.black));
			text.setTextSize(16);
		} else {
			text.setTextSize(14);
			text.setTextColor(mResources.getColor(R.color.dark));
		}
		switch (flag) {
		case 0:
			text.setText(data.get(position).circleTypeName);
			break;
		case 1:
			text.setText(data.get(position).couponTypeName);
			break;
		case 2:
			text.setText(moneyTypeStr[data.get(position).moneyType]);

			break;

		default:
			break;
		}

		return convertView;
	}

	public void setSelectItemIndex(int selectIndex) {
		mSelectedIndex = selectIndex;

	}

	public void addData(List<BusinessCircleListBean> data2, int flag) {
		this.data.clear();
		this.data = data2;
		this.flag = flag;
		notifyDataSetChanged();
	}

	public void clearIndex() {
		this.data.clear();
		mSelectedIndex = 0;
		notifyDataSetChanged();
	}
}
